import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;

/**
 * This class is Teacher
 */
public class Teacher implements Serializable{
	/**
	* Variables that will receive the input
	*/
	private String ID;
	private String Name;
	private int WeeklyHours;
	private int TotalHours;
	public Teacher(String iD, String name, int weeklyHours, int totalHours) {
		super();
		ID = iD;
		Name = name;
		WeeklyHours = weeklyHours;
		TotalHours = totalHours;
	}
	/**
	* Constructs an instance of Teacher.
	*/	
	public Teacher() {
		super();
	}
	/**
	* Constructs an instance of the user.
	* @param id
	*/	
	public Teacher(String id) {
		Teacher T = DBgetDetails(id);
		this.ID = id;
		this.Name = T.Name;
		this.WeeklyHours = T.WeeklyHours;
		this.TotalHours = T.TotalHours;
	}
	/**
	 * @return ID
	 */
	public String getID() {
		return ID;
	}
	/**
	 * @return Name
	 */
	public String getName() {
		return Name;
	}
	/**
	 * @return WeeklyHours
	 */
	public int getWeeklyHours() {
		return WeeklyHours;
	}
	/**
	 * @return TotalHours
	 */
	public int getTotalHours() {
		return TotalHours;
	}
	/**
	 * @param id
	 * @return Name
	 */
	public String DBgetName(String id){
		SQL s = new SQL(id,30);
		s.accept();
		String Name =(String) s.getMsg();
		return Name;
	}
	/**
	 * @param id
	 * @return Teacher
	 */
	public Teacher DBgetDetails(String id){
		SQL s = new SQL(id,34);
		s.accept();
		return (Teacher)s.getMsg();
	}
	/**
	 * @return LinkedList<String>
	 */
	public LinkedList<String> DBgetUnit(){
		SQL s = new SQL(this.ID,46);
		s.accept();
		return (LinkedList<String>)s.getMsg();
	}
	/**
	 * @return list
	 */
	public LinkedList<ClassInCourse> DBwhereTeach(){
		SQL s = new SQL(null,47);
		s.accept();
		LinkedList<ClassInCourse> list = (LinkedList<ClassInCourse>)s.getMsg();
		Iterator<ClassInCourse> itr = list.iterator();
		while (itr.hasNext())
			if (!itr.next().getTeacherID().equals(this.ID))
			 itr.remove();
		
		return list;
	}
	/**
	* This method show the Teachers data.
	*/
	public void DBSHOW()
	{
		System.out.println("Now Teachers data should show");
		
		LinkedList<String> units = DBgetUnit();
		LinkedList<ClassInCourse> WhereTeach = DBwhereTeach();
		Iterator<String> itr1 = units.iterator();
		Iterator<ClassInCourse> itr2 = WhereTeach.iterator();
		
		/////////////////////////Start of Print area////////////////////////////////
		String output = "";
		output+="Here are the units "+this.getName()+" teach:\n";
		while (itr1.hasNext()) 
		 output += itr1.next()+"\n";
		if (!itr2.hasNext()) output += this.getName()+" doesn't teach at any class or course";
		else
		{
			output += "Here are the classes and courses "+this.getName()+" teach:\n";
			while (itr2.hasNext()) 
			{
				ClassInCourse CIC = itr2.next();
				output +="Class: "+ CIC.getClassID()+" Course: "+CIC.getCourseID()+"\n";
			}
		}
			
							
		JTextArea outputArea = new JTextArea( 11, 60 );
		outputArea.setText( output );

		JOptionPane.showMessageDialog( null, outputArea,"Teacher Data",JOptionPane.INFORMATION_MESSAGE );
		/////////////////////////End of Print area////////////////////////////////
	}
}
